package roborally.util;

import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;
/**
 * This is an enum representing commands that control the program flow.

 * @version 3.0
 * @author Bart Opsomer 2de Bachelor Ingenieurswetenschappen Electrotechniek-Computerwetenschappen 
 * 		   Peter Opsomer 1ste Master Wiskundige IngenieursTechnieken
 */
public enum ComandWordsConstructs {
	// All the possible construct, with the textual representation of the enum
	SEQ("seq"),WHILE("while"),IF("if");
	// The textual representation of the enum 
	private String text;
	/**
	 * the constructor of the enum, that initials the textual representation of the enum
	 * @param word The textual representation of the enum
	 */
	@Raw
	ComandWordsConstructs(String word){
		this.text = word;
	}
	/**
	 * @return the text of this CommandWordBooleanOperator
	 */
	@Basic
	public String getText() {
		return this.text;
	}
	/**
	 * Get the CommandWordBooleanOperator that the given String represents.
	 * If no enum corresponds the the given String, null is returned
	 * 
	 * @param condition the String representing an CommandWordsCondition
	 * @return | result == null || result.getText().equals(condition)
	 */
	public static CommandWordsCondition fromString(String condition) {
		if (condition != null) {
			for (CommandWordsCondition c : CommandWordsCondition.values()) {
				if (condition.equals(c.getText())) {
					return c;
				}
			}
		}
		return null;
	}
	
	public Construct getConstruct(int start, int end) {
		return new Construct(start, end, this);
	}
}
